//
//  array_remove.hpp
//  suanfa
//
//  Created by 李贺 on 2021/11/24.
//

#ifndef array_remove_hpp
#define array_remove_hpp

#include <stdio.h>
#include <vector>
#include <iostream>

// 时间复杂度：O(n)
// 空间复杂度：O(1)
using namespace std;
class Solution_array_remove {
public:
    int removeElement(vector<int>& nums, int val) {
        int slowIndex = 0;
        for (int fastIndex = 0; fastIndex < nums.size(); fastIndex++) {
            if (val != nums[fastIndex]) {
                nums[slowIndex++] = nums[fastIndex];
            }
        }
        return slowIndex;
    }
    
    void testFunction() {
        vector<int> nums = vector<int>();
        nums.push_back(2);
        nums.push_back(2);
        nums.push_back(3);
        nums.push_back(2);
        nums.push_back(2);
        int result = this->removeElement(nums, 2);
        cout << "\n";
        cout << "result" << result ;
        cout << "\n";
    }
};



#endif /* array_remove_hpp */
